package uk.ac.ebi.dod.utils;

import uk.ac.ebi.dod.beans.Filter;

import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import java.util.List;

/**
 * @author Florian Reisinger
 * @version $Id$
 * @since x.y
 */
public class FilterListFormatter implements Converter {

    public FilterListFormatter() {

    }

    public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) {
      return null;
    }

    public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) {
      StringBuilder buff = new StringBuilder();

      if (object instanceof List) {
          List list = (List) object;
          for (Object o : list) {
              if (o instanceof Filter) {
                  Filter f = (Filter)o;
                  buff.append("[Filter: ");
                  buff = buff.append(f.getName());
                  buff.append(" with parameter: ");
                  buff = buff.append(f.getParameter());
                  buff.append("]<br/>");
              }
          }
      }
      return buff.toString();
    }

}
